package net.oxygen.upload.config;

import io.minio.MinioAsyncClient;
import io.minio.MinioClient;
import lombok.RequiredArgsConstructor;
import net.oxygen.upload.util.CustomMinioClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 * 功能：Minio连接配置
 * </p>
 *
 * @author 陈伟伟
 * @since 2023/12/15 16:39
 */
@Configuration
@RequiredArgsConstructor
public class MinioConfig {

    private final MinioProperties minioProperties;

    /**
     * 配置minio连接客户端
     */
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
    }

    /**
     * 配置用于分片上传的Minio连接客户端
     */
    @Bean
    public CustomMinioClient customMinioClient() {
        MinioAsyncClient asyncClient = MinioAsyncClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
        return new CustomMinioClient(asyncClient);
    }
}
